<template>
  <div class="search-result">
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <van-cell v-for="(item,index) in list" :key="index" :title="item.title" />
    </van-list>
  </div>
</template>
<script>
import { searchResult_api } from "@/api/user.js";
export default {
  props: ["resultVal"],
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1 || page,
    };
  },
  methods: {
    // 下拉列表  会立即执行一次
    async onLoad() {
      if (!this.resultVal.length) {
        return;
      }
      const { data: res } = await searchResult_api({
        page: this.page,
        per_page: 10,
        q: this.resultVal.trim(),
      });
      //   console.log(res, 123);
      this.list = [...this.list, ...res.data.results];
      this.loading = false;
      if (res.data.results.length) {
        this.page++;
      } else {
        this.finished = true;
      }
    },
  },
};
</script>
<style lang='less' scoped>
.search-result {
  padding-top: 105px;
}
</style>